package org.mipt.infsec.steganography.api;


import org.mipt.infsec.steganography.api.datastorage.image.Image;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

/**
 * Class helps to seek information into image file
 */
public abstract class ImageDecryptor implements Decryptor
{
    /**
     * helpful data which can contain specific information(like password)
     */
    String data;
    /**
     * processed image
     */
    Image image;
    /**
     * file which will contain
     */
    File outFile;

    /**
     * default constructor
     */
    public ImageDecryptor()
    {
    }
    /**
     * Constructor for ImageDecryptor class
     * @param file source file
     * @param data source data
     * @throws IOException when file with image doesn't exist
     */
    public ImageDecryptor(File file, String data) throws IOException
    {
        this.data = data;
        this.image = new Image(ImageIO.read(file));
    }

    /**
     * Consturctor for ImageDecryptor class
     * @param is InputStream which contain image
     * @param data source data
     * @throws IOException when InputStream throw IOException
     */
    public ImageDecryptor(InputStream is, String data) throws IOException
    {
        this.data = data;
        this.image = new Image(ImageIO.read(is));
    }

    /**
     * Constructor for ImageDecryptor class
     * @param image source image
     * @param data source data
     */
    public ImageDecryptor(BufferedImage image, String data)
    {
        this.data = data;
        this.image = new Image(image);
    }

    /**
     * Set file for result image
     * @param file distance file
     */
    public void setOutFile(File file)
    {
        this.outFile = file;
    }

    /**
     * Set file for result image
     * @param path name of distance file
     */
    public void setOutFile(String path)
    {
        this.outFile = new File(path);
    }

    /**
     * Get image
     * @return image
     */
    public Image getImage()
    {
        return image;
    }

    /**
     * Get data
     * @return data
     */
    public String getData()
    {
        return data;
    }

    /**
     * Get distance file
     * @return distance file
     */
    public File getOutFile()
    {
        return this.outFile;
    }

    /**
     * Start decryption process
     */
    public abstract Object decrypt();
}
